package com.ajk.server.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ajk.server.model.response.RegionDictRes;
import com.ajk.server.model.response.ResultList;
import com.ajk.server.model.response.ResultObject;
import com.ajk.server.service.RegionDictService;

@RestController
@RequestMapping("/region")
public class RegionDictController {
	
	@Autowired
	RegionDictService regionDictService;
	
	/**
	 * 获取所有区域
	 * @return
	 */
	@RequestMapping("/fetch_all")
	public ResultList<RegionDictRes> listAllWithCache(){
		ResultList<RegionDictRes> resultList = new ResultList<>();
		List<RegionDictRes> all = regionDictService.findAllWithCache();
		resultList.setItemList(all);
		return resultList;
	}
	/**
	 * 通过parentId查询
	 * @return
	 */
	@RequestMapping("/fetch_by_parent_id/{parentId}")
	public ResultList<RegionDictRes> listByParent(@PathVariable("parentId") Integer parentId){
		List<RegionDictRes> resultList = regionDictService.findByParentId(parentId);
		return new ResultList<>(resultList);
	}
	
	/**
	 * 通过Id查询
	 * @return
	 */
	@RequestMapping("/fetch_by_id/{id}")
	public ResultObject<RegionDictRes> listById(@PathVariable("id") Integer id){
		ResultObject<RegionDictRes> resultList = new ResultObject<>();
		RegionDictRes result = regionDictService.findRegionDictById(id);
		resultList.setDomain(result);
		return resultList;
	}
	
}
